$(function () {
    $("#user-confirm-password").blur(function () {
        var newPassword = $("#user-new-password").val();
        var confirmPassword = $("#user-confirm-password").val();
        if (newPassword != confirmPassword) {
            $("#repeatPassword").show();
            $("#savePassword").attr("disabled", "true");
        } else {
            $("#repeatPassword").hide();
            $("#savePassword").removeAttr("disabled");
        }

    });
/*    $("#user-new-password").blur(function () {
        var oldPassword = $("#user-old-password").val();
        var newPassword = $("#user-new-password").val();
        if (oldPassword == newPassword) {
            alert("不能与原密码相同！");
        }

    });*/
    $("#savePassword").click(function () {
        var oldPassword = $("#user-old-password").val();
        var newPassword = $("#user-new-password").val();
        var confirmPassword = $("#user-confirm-password").val();
        $.post(basePath + "/safety/password",
            {
                "oldPassword": oldPassword,
                "newPassword": newPassword,
                "confirmPassword": confirmPassword
            },function (result) {
                if (result == 0) {
                    alert("不能与原密码相同！");
                }else if (result == 1) {
                    alert("新密码不一致!");
                } else if (result == 2) {
                    alert("旧密码输入错误!");
                } else {
                    window.location.href = basePath + "/user/index";

                }
            })
    });
});